<template>
    <div class="mainDiv" style="padding: 10px;box-sizing: border-box;">
        <el-input placeholder="请输入诊断选项名称！" v-model="name" style="margin: 5px 0">
            <template slot="prepend">诊断选项</template>
        </el-input>
        <el-row>
            <el-col :span="12">
                <el-button @click.native="close" style="width:90%;display:block;">取消</el-button>
            </el-col>
            <el-col :span="12">
                <el-button type="success" @click.native="callSubmit" style="width:90%;display:block;" :loading="loading">确定</el-button>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import C from '@/common/common.js'
export default {
  name: 'userselectzhiwei',
  data () {
    return {
      RequestUrl: {},
      name: '',
      cid: '',
      loading: false
    }
  },
  mounted () {
    this.RequestUrl = C.getDatas()
    console.log(this.RequestUrl)
    if (this.RequestUrl) {
      this.name = this.RequestUrl.obj ? this.RequestUrl.obj.name : ''
      this.cid = this.RequestUrl.cid || ''
    }
  },
  methods: {
    async callSubmit (index) {
      if (/^\s*$/.test(this.name)) {
        C.error('诊断选项名称不能为空！')
        return false
      }
      let data = {
        cid: this.cid ? this.cid : this.RequestUrl.obj.pid,
        name: this.name,
        id: this.RequestUrl.obj ? this.RequestUrl.obj.id : 0
      }
      this.loading = true
      let res = await C.ajax('/organization/diagnosis/addoption', { data: JSON.stringify(data) }, 'post')
      this.loading = false
      if (res) {
        C.closeBrowserWindow(res)
      }
    },
    close () {
      C.closewin()
    }
  }
}
</script>